﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DBAccessLib;

namespace LineWatch_Web
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                lnkConfig.Visible = false;
                lnkReview.Visible = false;
                //lnkPositionCFG.Visible = false;
            }
        }

        protected void btnSignIn_Click(object sender, EventArgs e)
        {
            string userName = txtUserName.Text.Trim();
            string password = txtPassword.Text.Trim();
            bool canSetShift = false, loginSuccessfully = false, hasRight = false;
            if (!string.IsNullOrWhiteSpace(userName) && !string.IsNullOrWhiteSpace(password))
                loginSuccessfully = Account.SignedIn(userName, password, ref canSetShift, ref hasRight);
            if (loginSuccessfully)
            {
                Session["UserName"] = userName;
                Session["CanSetShift"] = canSetShift;
                Session["HasRight"] = hasRight;
                lnkConfig.Visible = true;
                lnkReview.Visible = true;
                //lnkPositionCFG.Visible = true;
                labInfo5.Text = String.Format("用户： {0}", txtUserName.Text);
                labInfo3.Visible = false;
                labInfo4.Visible = false;
                txtPassword.Visible = false;
                txtUserName.Visible = false;
                btnSignIn.Visible = false;
            }
            else
            {
                Session["UserName"] = string.Empty;
                Session["CanSetShift"] = false;
                Session["HasRight"] = false;
                labInfo5.Text = "用户名或密码不正确。";
            }
        }
    }
}